<template>
  <div>
    <BasicTable @register="registerTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            stopButtonPropagation
            :actions="[
              // {
              //   label: '评价信息',
              //   icon: 'clarity:info-standard-line',
              //onClick: handleProfileDesc.bind(null, record),
              // },
              {
                label: '实习信息',
                icon: 'clarity:info-standard-line',
                onClick: handleInternshipDesc.bind(null, record),
              },
              {
                label: '成绩信息',
                icon: 'clarity:info-standard-line',
                onClick: handleReportDesc.bind(null, record),
              },
            ]"
            :dropDownActions="[
              {
                label: '实习听课记录评分',
                icon: 'ic:outline-credit-score',
                onClick: handleLectureNoteDesc.bind(null, record),
              },
              {
                label: '教育实习教案评分',
                icon: 'ic:outline-credit-score',
                onClick: handleLessonPlanDesc.bind(null, record),
              },
              {
                label: '教研活动总结评分',
                icon: 'ic:outline-credit-score',
                onClick: handleTeachingStudyDesc.bind(null, record),
              },
              {
                label: '课堂教学评分',
                icon: 'ic:outline-credit-score',
                onClick: handleTeachingRecordDesc.bind(null, record),
              },
              {
                label: '师德表现评分',
                icon: 'ic:outline-credit-score',
                onClick: handleMoralScore.bind(null, record),
              },
              {
                label: '班主任实习工作评分',
                icon: 'ic:outline-credit-score',
                onClick: handleLeaderWorkDesc.bind(null, record),
              },
              {
                label: '编辑高校教师评语',
                icon: 'clarity:note-edit-line',
                onClick: handleGxRemark.bind(null, record),
              },
              {
                label: '编辑中学教师评语',
                icon: 'clarity:note-edit-line',
                onClick: handleZxRemark.bind(null, record),
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
    <ScoreEdit @register="registerScoreModal" />
    <RemarkEdit @register="registerRemarkModal" />
    <ReportDesc @register="registerReportDescModal" />
    <InternshipDesc @register="registerInternshipDescModal" />
  </div>
</template>
<script lang="ts" setup>
  import { BasicTable, TableAction, useTable } from "/@/components/Table";
  import { useModal } from "/@/components/Modal";
  import ScoreEdit from "/@/views/default/practical/ScoreEdit.vue";
  import ReportDesc from "./components/ReportDesc.vue";
  import RemarkEdit from "./components/RemarkEdit.vue";
  import InternshipDesc from "./components/InternshipDesc.vue";
  import { useRouter } from "vue-router";
  import { defaultActionColumn, defaultTableSettings } from "/@/hooks/core/useDefault";
  import { searchFormConfig } from "/@/views/teacher/practical/member/member.data";
  import { getUserListByTutorApi } from "/@/api/core/group";
  import { teacherBasicColumns } from "/@/views/default/data";
  import {
    getInfoByUserIdApi,
    getRemarkByUserIdApi,
    getReportByUserIdApi,
    getTeacherMoralScoreApi,
  } from "/@/api/core/internInfo";
  import { PracTypeEnum, RemarkTypeEnum } from "/@/enums/typeEnum";

  const [registerTable] = useTable({
    title: "实习生信息",
    api: getUserListByTutorApi,
    rowKey: "userId",
    immediate: false,
    useSearchForm: true,
    columns: teacherBasicColumns,
    formConfig: searchFormConfig,
    ...defaultTableSettings,
    actionColumn: {
      width: 280,
      ...defaultActionColumn,
    },
  });

  const [registerReportDescModal, { openModal: openReportDescModal }] = useModal();

  async function handleReportDesc(record) {
    openReportDescModal(true, await getReportByUserIdApi(record.userId));
  }

  const [registerInternshipDescModal, { openModal: openInternshipDescModal }] = useModal();

  async function handleInternshipDesc({ userId }) {
    openInternshipDescModal(true, await getInfoByUserIdApi(userId));
  }

  const router = useRouter();

  function handleLectureNoteDesc(data) {
    router.push({
      name: "LectureNoteList",
      query: { userId: data.userId, userName: data.userName },
    });
  }

  function handleLessonPlanDesc(data) {
    router.push({
      name: "LessonPlanList",
      query: { userId: data.userId, userName: data.userName },
    });
  }

  function handleTeachingStudyDesc(data) {
    router.push({
      name: "TeachingStudyList",
      query: { userId: data.userId, userName: data.userName },
    });
  }

  function handleTeachingRecordDesc(data) {
    router.push({
      name: "TeachingRecordList",
      query: { userId: data.userId, userName: data.userName },
    });
  }

  const [registerScoreModal, { openModal: openScoreModal }] = useModal();

  async function handleMoralScore(data) {
    const score = await getTeacherMoralScoreApi(data.userId as unknown as number);
    openScoreModal(true, {
      score,
      userId: data.userId,
      target: PracTypeEnum.TeacherMoral,
    });
  }

  function handleLeaderWorkDesc(data) {
    router.push({
      name: "LeaderWorkDesc",
      query: { userId: data.userId },
    });
  }

  const [registerRemarkModal, { openModal: openRemarkModal }] = useModal();

  async function handleGxRemark(data) {
    const { univRemark } = await getRemarkByUserIdApi(data.userId);
    openRemarkModal(true, {
      userId: data.userId,
      content: univRemark,
      remarkType: RemarkTypeEnum.univRemark,
    });
  }

  async function handleZxRemark(data) {
    const { schRemark } = await getRemarkByUserIdApi(data.userId);
    openRemarkModal(true, {
      userId: data.userId,
      content: schRemark,
      remarkType: RemarkTypeEnum.schRemark,
    });
  }
</script>
